package it.uniroma2.art.owlart.model.syntax.manchester;

import it.uniroma2.art.owlart.models.OWLModel;
import it.uniroma2.art.owlart.exceptions.ModelUpdateException;
import it.uniroma2.art.owlart.model.ARTBNode;
import it.uniroma2.art.owlart.model.ARTResource;

import java.util.ArrayList;
import java.util.ListIterator;


public class ObjectUnionOf {
	private int numb;//numero degli oggetti che sono in or tra loro
	ArrayList<ObjectIntersectionOf> or;
	public OWLModel model;
	public ARTResource resource;

	public ObjectUnionOf(OWLModel mod) {
		numb=0;
		or=new ArrayList<ObjectIntersectionOf>();
		model=mod;
	}

	public int getElements() {
		return numb;
	}

	public void addElement(ObjectIntersectionOf toAdd) {
		or.add(toAdd);
		numb++;
	}
	public String toString() {
	    	String res="conj----dim or:"+or.size();
		return res;
	}

	public void createOntology() throws ModelUpdateException {
		ARTBNode b=model.createBNode();
		ArrayList<ARTResource> res=new ArrayList<ARTResource>();
		ListIterator<ObjectIntersectionOf> orIterator=or.listIterator();
		while(orIterator.hasNext()) {
			res.add(orIterator.next().computeIntersection());
		}
		if(or.size()==1) {
		    resource=or.get(0).resource;
		    return;
		}
		model.addUnionOf(b.getID(), res);

		resource=b;
	}
}
